#ifndef __LOGINSTREAM
#define __LOGINSTREAM

#include "..\Streams\Stream.h"
#include "LoginObject.h"
#include "..\Log\Log.h"



class LoginStream : public virtual Stream
{
private:
	LoginObject m_lo;
	Log m_log;
	bool m_loggedin;

public:
	LoginStream()
	{
		m_loggedin = false;
	}

	virtual ~LoginStream() {}

	bool loggedin()
	{
		return m_loggedin;
	}

	LoginPacket * login(int usernumber, char * passwd)
	{
		LoginPacket * lp = new LoginPacket();
		memset(lp->passwd, 0, strlen(passwd));

		lp->userid = usernumber;
		strcpy(lp->passwd, passwd);

		return lp;
	}

	bool client_login(LoginPacket * lp)
	{
		LoginObject lo;
		authentication a;
		if (lp->userid == 1045661)
		{
			a.news = 1;
			strcpy(lo.email,"smleighton@gmail.com");
			strcpy(lo.fname,"Sean");
			strcpy(lo.lname,"Leighton");
			strcpy(lo.password, lp->passwd);
			lo.userid = lp->userid;
			lo.a = a;
			lp->object = lo;
			return true;
		}
		return false;
	}

	bool process_login_response(LoginPacket * lp)
	{
		if (lp->object.userid > 0)
		{
			char message[1024];
			m_loggedin = true;
			sprintf(message, "Login response: %d, %s\n", lp->object.userid, lp->object.email);
			m_log.TRACE(2, message);
			sprintf(message, "News value: %d\n", lp->object.a.news);
			m_log.TRACE(2, message);
		}
		return m_loggedin;
	}

	bool logout()
	{
	}

	bool relogin()
	{
	}

	bool resetpassword(char * passwd)
	{
	}

	bool setauthentication()
	{
	}
};

#endif